﻿using Cimbalino.Phone.Toolkit.Converters;
using MVBuddy.Common.Resources;
using System;
using System.Globalization;

namespace MVBuddy.Converters
{
    public class IntToDescriptionConverter : MultiValueConverterBase
    {
        public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length == 2 && values[0] != null && values[1] != null)
            {
                int itemCount = (int)values[0];
                string description = values[1] as string;

                if (!string.IsNullOrEmpty(description))
                {
                    string formatTemplate;

                    switch (itemCount)
                    {
                        case 0:
                            formatTemplate = AppResources.NoNewTemplate;
                            break;
                        case 1:
                            formatTemplate = AppResources.ViewSingularTemplate;
                            break;
                        default:
                            formatTemplate = AppResources.ViewPluralTemplate;
                            break;
                    }

                    return string.Format(formatTemplate, itemCount, description);
                }
            }

            return string.Empty;
        }

        public override object[] ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
